
package textmining.gpanalysis;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Set;

import data.KeywordVector;

/**
 *
 * @author ibrahimsabek
 */
public class VectorXmlBuilder {

    private static final String folderPath = "C:/vectors";
    public VectorXmlBuilder(){}

    public void createVectorXml(KeywordVector vector) throws FileNotFoundException{
        File vectorFile = new File(folderPath + "/v"+vector.getVectorID()+".xml");
        PrintWriter vectorWriter = new PrintWriter(vectorFile);

        String vectorHeader = "<vector id=\"" +vector.getVectorID() +"\">";
        String vectorTail = "</vector>";
        String keywordHolder = "";
        
        vectorWriter.println(vectorHeader);

        Set<String> keyset = vector.getData().keySet();
        for(String key : keyset){
            keywordHolder = "<keyword name=\"" +key+"\">"+vector.getData().get(key)+"</keyword>";
            vectorWriter.println(keywordHolder);
        }

        vectorWriter.println(vectorTail);
        vectorWriter.close();

        
    }
}
